#include "character.h"

_variety_character Character::arrChar[8] = {_letter_small, _letter_big,_digit,_operator,_bracket,_punctuation,_separator,_not_match};
QString Character::strVariety_en[8] = {"_letter_small","_letter_big","_digit","_operator","_bracket","_punctuation","_separator","_not_match"};
QString Character::strVariety_cn[8] = {"小写字母","大写字母","阿拉伯数字","运算符","括号","标点符号","分隔符","无法匹配"};
_variety_character Character::IntToVariety(int n) {
    if(n < 0 || n > _not_match) {
        return _not_match;
    }
    return arrChar[n];
}
QString Character::IntToVarietyString_en(int n) {
    if(n < 0 || n > _not_match) {
        return strVariety_en[_not_match];
    }
    return strVariety_en[n];
}
QString Character::IntToVarietyString_cn(int n) {
    if(n < 0 || n > _not_match) {
        return strVariety_cn[_not_match];
    }
    return strVariety_cn[n];
}

_variety_character Character::String_cnToVariety(QString str)
{
    for(int i = 0;i < 8;i++) {
        if(str == strVariety_cn[i]) {
            return IntToVariety(i);
        }
    }
    return IntToVariety(7);
}

Character::Character() {}
Character::Character(_variety_character v,char c) {
    variety = v;
    content = c;
}
Character::Character(字符类型 v,char c) {
    variety = arrChar[v];
    content = c;
}

_variety_character Character::GetVariety() {
    return variety;
}
_variety_character Character::GetVariety() const{
    return variety;
}
char Character::GetContent() {
    return content;
}
char Character::GetContent() const{
    return content;
}

void Character::SetVariety(_variety_character v) {
    variety = v;
}
void Character::SetVariety(字符类型 v) {
    variety = arrChar[v];
}
void Character::SetContent(char c) {
    content = c;
}

bool Character::operator<(const Character& other) {
    return (variety < other.GetVariety() || (variety == other.GetVariety() && content < other.GetContent()));
}
bool Character::operator<(const Character& other) const{
    return (variety < other.GetVariety() || (variety == other.GetVariety() && content < other.GetContent()));
}
bool Character::operator==(const Character& other) {
    return (variety == other.GetVariety() && content == other.GetContent());
}
bool Character::operator==(const Character& other) const{
    return (variety == other.GetVariety() && content == other.GetContent());
}
bool Character::operator==(char value) {
    return (content == value);
}
bool Character::operator==(char value) const{
    return (content == value);
}
bool Character::operator==(QChar value) {
    return (content == value);
}
bool Character::operator==(QChar value) const{
    return (content == value);
}

QString Character::GetVarietyString_en () {
    return strVariety_en[variety];
}
QString Character::GetVarietyString_en () const{
    return strVariety_en[variety];
}
QString Character::GetVarietyString_cn () {
    return strVariety_cn[variety];
}
QString Character::GetVarietyString_cn () const{
    return strVariety_cn[variety];
}

